package com.network.topo.descover;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool {
	private static ExecutorService pool = Executors.newFixedThreadPool(20);
	
	private  static Map<String,IdentifyThread> threadMap = new HashMap<String,IdentifyThread>();
	public static int ipCount = 0;
	public static void run(IdentifyThread thread){
		try{
			threadMap.put(thread.getIpAddr(),thread);
			
			pool.execute(thread);
			
		}
		catch(Exception ex){
			
		}
	}
	public static void init(){
		threadMap.clear();
		ipCount = 0;
	}
	public static void shutDown(){
		pool.shutdown();
	}
	public synchronized static void removeOne(String ipAddr){
		threadMap.remove(ipAddr);
		ipCount++;
	
	}
	public static boolean isShutdown(){
		return pool.isShutdown();
	
	}
	public static boolean isAlive(){
		return threadMap.size() >0 ?true:false;
	
	}
	public static boolean isTerminated(){
		return pool.isTerminated();
	
	}
}
